<html>
<head><meta charset="utf-8"><title>reviewing log::kv · t-libs · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/index.html">t-libs</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html">reviewing log::kv</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202507185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/202507185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#202507185">(Jun 30 2020 at 23:21)</a>:</h4>
<p>Hey all! We've had an unstable API for structured logging in the log crate for some time now. I think it's almost ready to stabilize (just have one open PR to get over the line) but would love an API review from Libs and anybody who wants to check it out. Would anybody here be up for a run through via Zoom sometime in the next week or two?</p>



<a name="202529970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/202529970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#202529970">(Jul 01 2020 at 04:31)</a>:</h4>
<p>I'd be happy to look over the API.</p>



<a name="202553479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/202553479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#202553479">(Jul 01 2020 at 10:34)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="143274">@Amanieu</span> <span aria-label="bow" class="emoji emoji-1f647" role="img" title="bow">:bow:</span> I’m just waiting on a stabilization PR in <code>rust-lang</code> that rounds out some features in <code>log</code> then it should be ready to go</p>



<a name="203816658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/203816658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#203816658">(Jul 14 2020 at 10:07)</a>:</h4>
<p>There is one point I am not sure from that, how does one preserve the context for key value logging? If the same key value is used in multiple places, so it needs to be repeated?</p>
<p>Also, looking at the code it does seemed complicated. I didn't know it will be so complicated at first.</p>



<a name="203946330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/203946330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#203946330">(Jul 15 2020 at 12:07)</a>:</h4>
<p><span class="user-mention" data-user-id="225422">@pickfire</span> I believe most of the complexity comes from not forcing any allocations whatsoever: every value is passed by reference and converted into a <code>log::kv::Value</code> which doesn't have any inherent cost associated with it.</p>



<a name="203946338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/203946338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#203946338">(Jul 15 2020 at 12:07)</a>:</h4>
<p>(hoping I got that right haha)</p>



<a name="203946414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/203946414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#203946414">(Jul 15 2020 at 12:08)</a>:</h4>
<p><span class="user-mention" data-user-id="225422">@pickfire</span> not sure I follow your first question though: what do you mean by "used in multiple places, so it needs to be repeated"? -- like multiple log statements referencing the same values?</p>



<a name="204078234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/204078234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#204078234">(Jul 16 2020 at 12:52)</a>:</h4>
<p><span class="user-mention" data-user-id="211722">@Yoshua Wuyts</span> Yes, sort of like some scoping.</p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">a</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">log</span>::<span class="n">info</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;hello&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span>: <span class="nc">x</span><span class="w"> </span><span class="p">});</span><span class="w"></span>
<span class="w">    </span><span class="n">b</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">b</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">2</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">log</span>::<span class="n">info</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;world&quot;</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span>: <span class="nc">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span>: <span class="nc">y</span><span class="w"> </span><span class="p">});</span><span class="w">  </span><span class="c1">// repeated structure</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>I also wonder if there is any way to buffer the log and flush it once at the end of each task. This is useful when running multiple threads but wanting to read the logs in a single threaded version since it is easier to read.</p>



<a name="204078492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/204078492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#204078492">(Jul 16 2020 at 12:54)</a>:</h4>
<p><span class="user-mention" data-user-id="225422">@pickfire</span> there's nothing really stopping anyone from building a logger that does exactly that — at least from <code>log</code>'s perspective</p>



<a name="204078583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/204078583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#204078583">(Jul 16 2020 at 12:55)</a>:</h4>
<p>But how about the other thing I mentioned? So it needs to be duplicated for log from a low level perspective?</p>



<a name="204078671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/204078671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pickfire <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#204078671">(Jul 16 2020 at 12:56)</a>:</h4>
<p>Also, can it supports <code>log::info!("hello", { x })</code> as an alias to <code>log::info!("hello", { x: x })</code>?</p>



<a name="204148616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/204148616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#204148616">(Jul 16 2020 at 21:57)</a>:</h4>
<p><span class="user-mention" data-user-id="225422">@pickfire</span> There is a fair bit going on in there, especially inside the <code>Value</code> struct, but I've been thinking of hoisting <code>Value</code> out into its own crate somewhere, because there's some interest from the <code>tracing</code> folks in using it too.</p>



<a name="204148767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/219381-t-libs/topic/reviewing%20log%3A%3Akv/near/204148767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/219381-t-libs/topic/reviewing.20log.3A.3Akv.html#204148767">(Jul 16 2020 at 21:58)</a>:</h4>
<p>There are so many things we could do with macros, like also letting you associate a <code>impl std::error::Error</code> explicitly</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>